package com.jixiantubu.adapter;

import image.SmartImageView;

import java.util.ArrayList;
import java.util.List;

import com.example.jixiantubu.R;
import com.jixiantubu.bean.PostInfoBean;
import com.jixiantubu.util.EllipsizeText;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.BitmapUtils;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TieziShouyeAdapter extends BaseAdapter {
	List<PostInfoBean> list = new ArrayList<PostInfoBean>();
	Context context;
	LayoutInflater mInflater;
	ViewHolder mHolder;
	 BitmapFactory.Options opts = null;
	public TieziShouyeAdapter() {
		super();
	}

	public TieziShouyeAdapter(Context context, List<PostInfoBean> list) {
		super();
		this.list = list;
		this.context = context;
		mInflater = LayoutInflater.from(context);
	}

	public List<PostInfoBean> getList() {
		return list;
	}

	public void setList(List<PostInfoBean> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.tiezi_shouye_item, null);
			mHolder = new ViewHolder();
			mHolder.imageView1 = (SmartImageView) convertView
					.findViewById(R.id.post_user_imgview);
			mHolder.imageView2 = (SmartImageView) convertView
					.findViewById(R.id.post_scan_imgview);
			mHolder.imageView3 = (SmartImageView) convertView
					.findViewById(R.id.post_isFine_imgview);
			mHolder.imageView4 = (ImageView) convertView
					.findViewById(R.id.post_info_img);
			mHolder.textView1 = (TextView) convertView
					.findViewById(R.id.username_textview);
			mHolder.textView2 = (TextView) convertView
					.findViewById(R.id.createTime_textview);
			mHolder.textView3 = (TextView) convertView
					.findViewById(R.id.post_scan_textview);
			mHolder.textView4 = (TextView) convertView
					.findViewById(R.id.post_title_textview);
			mHolder.textView5 = (EllipsizeText) convertView
					.findViewById(R.id.post_content_textview);
			convertView.setTag(mHolder);
		} else {
			mHolder = (ViewHolder) convertView.getTag();
		}
		mHolder.textView1.setText(list.get(position).getUser_nickname());
		mHolder.textView2.setText(list.get(position).getCreateTime());
		mHolder.textView3.setText(String.valueOf(list.get(position)
				.getReplay_count()));
		mHolder.textView4.setText(list.get(position).getTitle());
		mHolder.textView5.setText(list.get(position).getContent());
		String url1="http://"+MyApplication.getIP()+":8080/Jinnang/img/"+list
				.get(position).getUser_imgPath();
		mHolder.imageView1.setImageUrl(url1);
		Log.e("-----", list.get(position).getPl_img().toString());
		if (list.get(position).getPl_img().size()==0) {
			mHolder.imageView4.setVisibility(View.GONE);
		}else{
		String url2="http://"+MyApplication.getIP()+":8080/Jinnang/img/"+list
				.get(position).getPl_img().get(0);
		BitmapUtils bitmapUtils=new BitmapUtils(context);
		bitmapUtils.display(mHolder.imageView4,url2);
		}
		if (list.get(position).isFine()) {
			mHolder.imageView3.setVisibility(View.VISIBLE);
		} else {
			mHolder.imageView3.setVisibility(View.GONE);
		}
		return convertView;
	}
	class ViewHolder {
		SmartImageView imageView1;
		SmartImageView imageView2;
		SmartImageView imageView3;
		ImageView imageView4;
		TextView textView1;
		TextView textView2;
		TextView textView3;
		TextView textView4;
		EllipsizeText textView5;
	}
}
